package com.atguigu.lease.web.admin.schedu;

import com.atguigu.lease.model.entity.LeaseAgreement;
import com.atguigu.lease.model.enums.LeaseStatus;
import com.atguigu.lease.web.admin.service.LeaseAgreementService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.Date;

@Component
public class schedulTask {
    @Autowired
    private LeaseAgreementService leaseAgreementService;

    @Scheduled(cron = "0 0 0 * * ?")
    public void updateStatus(){

        LambdaQueryWrapper<LeaseAgreement> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.lt(LeaseAgreement::getLeaseEndDate,new Date())
                        .eq(LeaseAgreement::getStatus, LeaseStatus.EXPIRED)
                                .in(LeaseAgreement::getStatus,2,5,7);
        leaseAgreementService.update(queryWrapper);
    }
}
